class code3 {
    //方法二：计数+hash
    public List<List<String>> groupAnagrams(String[] strs) {
        List<List<String>> ret = new ArrayList<>();
        Map<String,List<String>> map = new HashMap<>();
        //把字母放入hash
        for(String s:strs) {
            // char[] str = s.toCharArray();
            // Arrays.sort(str);
            int[] count = new int[26];
            for(char c:s.toCharArray()) {
                count[c-'a']++;
            }
            StringBuilder sb = new StringBuilder();
            for(int i:count) {
                sb.append(i+"_");
            }
            String key = sb.toString();
            List<String> list = map.getOrDefault(key,new ArrayList<>());
            list.add(s);
            map.put(key,list);
        }
        //结果list统计到ret
        for(String key:map.keySet()) {
            ret.add(map.get(key));
        }
        return ret;
    }
}